package com.kaifamiao.service.impl;

import com.kaifamiao.entity.Customer;
import com.kaifamiao.mapper.CustomerMapper;
import com.kaifamiao.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    private CustomerMapper customerMapper;

    @Override
    public boolean save(Customer c) {
        int count = customerMapper.persist(c);
        return count == 1 ;
    }

    @Override
    public boolean update(Customer c) {
        return customerMapper.update(c) == 1 ;
    }

    @Override
    public boolean remove(Integer id) {
        return customerMapper.remove(id) == 1 ;
    }

    @Override
    public Customer find(Integer id) {
        return customerMapper.find(id);
    }

    @Override
    public List<Customer> findAll() {
        return customerMapper.findAll();
    }

    @Override
    public boolean exists(String email, String tel) {
        Customer c = customerMapper.findByEmailOrTel(email, tel);
        return c != null;
    }

    @Override
    public Customer find(String email, String tel) {
        return customerMapper.findByEmailOrTel(email, tel);
    }

    public CustomerMapper getCustomerMapper() {
        return customerMapper;
    }

    @Autowired
    public void setCustomerMapper(CustomerMapper customerMapper) {
        this.customerMapper = customerMapper;
    }
}
